---@class PoolManager
---@deprecated 该类已废弃 参考 ComponentPoolMgr.lua
---@field New fun(templateItem:table):PoolManager
PoolManager = Class("PoolManager")
local t = PoolManager
function t:ctor(templateItem)
    self.template = templateItem
    self.unUseList = {}
    self.usedList = {}
end
---@param obj FairyGUI.GComponent [传入obj 获得其绑定的lua table ,如果没有则创建一个新的lua table
---@return table [返回绑定好的lua table
function t:GetBindScript(obj)
    if not obj then return nil end
    local id = obj.id
    local item = self.usedList[id]
    if item then
        return item
    end
    local count = #self.unUseList
    local item
    if count > 0 then
        item = table.remove(self.unUseList,count)
    else
        if self.template == nil then
            logError("模板为空，无法创建table")
            return nil
        end
        if self.template.New == nil then
            logError("未定义New方法，无法创建table")
            return nil
        end
        item = self.template.New()
    end
    if item.Bind then
        item:Bind(obj)
    else
        logError("未定义Bind方法，无法绑定obj")
    end
    self.usedList[id] = item
    return item
end
---界面销毁时调用，释放资源
function t:OnDestroy()
    if self.usedList then
        for k,v in pairs(self.usedList) do
            if v.OnDestroy then
                v:OnDestroy()
            end
        end
    end
    self.template = nil
    self.unUseList = nil
    self.usedList = nil
end
return PoolManager